
class Chain:
    def __init__(self,value,nex):
        ## 采用头节点不存储数据的方式
        self.val = value
        self.next = nex
    def add(self, value):
        chain = Chain(value, None)
        p = self
        while p.next:
            p = p.next
        p.next = chain

    # 遍历链表
    def traverse(self):
        lis = []
        while self.next:
            lis.append(self.next.val)
            self = self.next
        print(lis)


def remove_elem_from_chain(lis, value):
    # 初始化链表
    chain = Chain(0,None)
    if len(lis) == 0:
        print("[]")
    else:
        for i in range(len(lis)):
            chain.add(lis[i])
        p = chain
        while p.next:
            if p.next.val == value:
                p.next = p.next.next
            else:
                p = p.next
        chain.traverse()



if __name__ == "__main__":
    lis = []
    value = 4
    remove_elem_from_chain(lis, value)
    pass